package com.orphan.limitedDeal.controller;

import com.orphan.limitedDeal.po.PromotionOrders;
import com.orphan.limitedDeal.service.impl.PromotionOrderServiceImpl;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Random;
import java.util.UUID;

@RestController
@RequestMapping("/promotionOrder")
public class PromotionOrderController {
    @Autowired
    PromotionOrderServiceImpl promotionOrderService;
    @PostMapping("/buyGoods")
    public boolean addPromotionOrder(String goodsId,String goodsName, String gooodsType, String goodsPrice, String promotion,String goodsTag,String payMethod,String buyNum){
        PromotionOrders promotionOrders =new PromotionOrders();
        promotionOrders.setGoodsId(Integer.parseInt(goodsId));
//        promotionOrders.setGoodsName(goodsName);
//        promotionOrders.setOrderNo("'"+promotionOrders.getGoodsId()+promotionOrders.getBuyNum()+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+"'");
       promotionOrders.setOrderNo(UUID.randomUUID().toString().replace("-", ""));
        promotionOrders.setTotalAmount(Double.parseDouble(goodsPrice)*Double.parseDouble(promotion)*Integer.parseInt(buyNum));

//        promotionOrders.setGoodsType(gooodsType);
//        promotionOrders.setGoodsPrice(Double.parseDouble(goodsPrice)*Double.parseDouble(promotion));
//        promotionOrders.setGoodsTag(Integer.parseInt(goodsTag));
        promotionOrders.setOrderTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        promotionOrders.setPayMethod(Integer.parseInt(payMethod));
        promotionOrders.setBuyNum(Integer.parseInt(buyNum));
        System.out.println("promotionOrders = " + promotionOrders);
        boolean flage=promotionOrderService.addPromotionOrder(promotionOrders);
        System.out.println("flage = " + flage);
        return flage;
    }
}
